package cn.yunhe.controller;

import cn.yunhe.entity.User;
import cn.yunhe.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/UserRegServlet")

public class UserRegServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name=request.getParameter("userName,");
        String pwd=request.getParameter("passWord");
        String phoneNumber=request.getParameter("phoneNumber");
        int stage=0;
        User user=new User(name,pwd,stage,phoneNumber);
        UserService userService=new UserService();
        boolean flag=userService.userReg(user);

        if(flag){
            PrintWriter out=response.getWriter();
            out.print("<script>alert('注册成功');window.location.href='reg-result.jsp'</script>");
        }else{
            response.sendRedirect("register.jsp");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
